package com.qf.dao.impl;

import com.qf.dao.UserDao;
import com.qf.entity.User;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

/**
 * @Author:zhangyang
 * @Date: 2020-12-8 7:02
 * @Version 1.0
 */
public class UserDaoImpl  implements UserDao {

    private SqlSessionFactory sqlsessionFactory ;
    public  UserDaoImpl(SqlSessionFactory sqlSessionFactory){
        this.sqlsessionFactory = sqlSessionFactory ;
    }

    /**
     * 执行查询所有
     * @return
     */
    @Override
    public List<User> findAll() {

        //1.使用工厂创建sqlSession对象
        SqlSession session = sqlsessionFactory.openSession();
        //2.使用session执行查询方法
        List<User> list = session.selectList("com.qf.dao.UserDao.findAll");
        session.close();
        return list;
    }
}
